package com.hourse.service;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hourse.mapper.HouseMapper;
import com.hourse.pojo.House;
import com.hourse.util.IdWorker;
import com.hourse.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class HouseService {
    @Autowired
    private HouseMapper houseMapper;
    @Autowired
    private IdWorker idWorker;

    public List<House> list() {
        return houseMapper.selectByExample(null);
    }


    public void houseAdd(House house) {

        house.setId(idWorker.nextId());

        houseMapper.insert(house);
    }


    public void houseUp(House house) {

        houseMapper.updateByPrimaryKey(house);

    }

    public void houseDelete(Long id) {

        houseMapper.deleteByPrimaryKey(id);

    }

    public PageResult findAll(Integer page, Integer size) {

        PageHelper.startPage(page, size);

        Page<House> hpage=   (Page<House>) houseMapper.selectByExample(null);

        return new PageResult(hpage.getTotal(),hpage.getResult());
    }




}
